/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CadastroDisciplinasIFrame.java
 *
 * Created on 27/06/2012, 15:51:50
 */
package br.com.fatecpg.operon.frames;

import br.com.fatecpg.operon.Conexao;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
/**
 *
 * @author Jreaver
 */


public class CadastroDisciplinasIFrame extends javax.swing.JInternalFrame {





    /** Creates new form CadastroDisciplinasIFrame */
    public CadastroDisciplinasIFrame() {
        initComponents();
    }
    
    
  
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        sigla = new javax.swing.JLabel();
        siglaTextField = new javax.swing.JTextField();
        id = new javax.swing.JLabel();
        idTextField = new javax.swing.JTextField();
        titulo = new javax.swing.JLabel();
        tituloTextField = new javax.swing.JTextField();
        curso = new javax.swing.JLabel();
        cursoTextField = new javax.swing.JTextField();
        periodoLabel = new javax.swing.JLabel();
        periodoComboBox = new javax.swing.JComboBox();
        cargahoraria = new javax.swing.JLabel();
        cargahorariaTextField = new javax.swing.JTextField();
        ementa = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        ementajTextArea = new javax.swing.JTextArea();
        objetivos = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        objetivosjTextArea = new javax.swing.JTextArea();
        cadastrar = new javax.swing.JButton();
        cancelar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setTitle("Cadastro das Disciplinas");
        getContentPane().setLayout(null);

        sigla.setText("Sigla:");
        getContentPane().add(sigla);
        sigla.setBounds(290, 10, 26, 14);

        siglaTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                siglaTextFieldActionPerformed(evt);
            }
        });
        getContentPane().add(siglaTextField);
        siglaTextField.setBounds(320, 10, 100, 20);

        id.setText("ID:");
        getContentPane().add(id);
        id.setBounds(10, 14, 15, 14);
        getContentPane().add(idTextField);
        idTextField.setBounds(35, 11, 80, 20);

        titulo.setText("Título:");
        getContentPane().add(titulo);
        titulo.setBounds(10, 92, 30, 14);
        getContentPane().add(tituloTextField);
        tituloTextField.setBounds(44, 89, 220, 20);

        curso.setText("Curso:");
        getContentPane().add(curso);
        curso.setBounds(10, 40, 32, 14);
        getContentPane().add(cursoTextField);
        cursoTextField.setBounds(52, 37, 210, 20);

        periodoLabel.setText("Período:");
        getContentPane().add(periodoLabel);
        periodoLabel.setBounds(290, 50, 40, 14);

        periodoComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Vespertino", "Noturno" }));
        periodoComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                periodoComboBoxActionPerformed(evt);
            }
        });
        getContentPane().add(periodoComboBox);
        periodoComboBox.setBounds(340, 40, 76, 20);

        cargahoraria.setText("Carga Horária Semanal:");
        getContentPane().add(cargahoraria);
        cargahoraria.setBounds(10, 66, 114, 14);
        getContentPane().add(cargahorariaTextField);
        cargahorariaTextField.setBounds(134, 63, 130, 20);

        ementa.setText("Ementa:");
        getContentPane().add(ementa);
        ementa.setBounds(10, 141, 40, 14);

        ementajTextArea.setColumns(20);
        ementajTextArea.setRows(5);
        jScrollPane2.setViewportView(ementajTextArea);

        getContentPane().add(jScrollPane2);
        jScrollPane2.setBounds(10, 161, 410, 96);

        objetivos.setText("Objetivos:");
        getContentPane().add(objetivos);
        objetivos.setBounds(10, 268, 50, 14);

        objetivosjTextArea.setColumns(20);
        objetivosjTextArea.setRows(5);
        jScrollPane1.setViewportView(objetivosjTextArea);

        getContentPane().add(jScrollPane1);
        jScrollPane1.setBounds(10, 288, 410, 100);

        cadastrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/fatecpg/operon/icons/48px-Crystal_Clear_action_edit_add.png"))); // NOI18N
        cadastrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cadastrarActionPerformed(evt);
            }
        });
        getContentPane().add(cadastrar);
        cadastrar.setBounds(130, 400, 60, 60);

        cancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/fatecpg/operon/icons/48px-Crystal_Clear_action_edit_remove.png"))); // NOI18N
        getContentPane().add(cancelar);
        cancelar.setBounds(190, 400, 60, 60);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/fatecpg/operon/imagens/escola_1024x768.jpg"))); // NOI18N
        getContentPane().add(jLabel1);
        jLabel1.setBounds(0, 0, 840, 610);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-448)/2, (screenSize.height-502)/2, 448, 502);
    }// </editor-fold>//GEN-END:initComponents

    private void siglaTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_siglaTextFieldActionPerformed
       // TODO add your handling code here:
    }//GEN-LAST:event_siglaTextFieldActionPerformed

    private void periodoComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_periodoComboBoxActionPerformed

        // TODO add your handling code here:}//GEN-LAST:event_periodoComboBoxActionPerformed
    }
        private void cadastrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cadastrarActionPerformed
       String codigo = idTextField.getText();
        String sigla = siglaTextField.getText();
        String curso = cursoTextField.getText();
        String periodo = periodoComboBox.getActionCommand();
        String carga = cargahorariaTextField.getText();
        String titulo = tituloTextField.getText();
        String ementa = ementajTextArea.getText();
        String objetivos = objetivosjTextArea.getText();


        String SQL="INSERT INTO operon.DISCIPLINAS VALUES("+codigo+",'"+sigla+"','"+curso+"','"+periodo+"','"+carga+"','"+ementa+"','"+objetivos+"','"+titulo+"')";
        try{
            Conexao.con.createStatement().execute(SQL);
            this.dispose();

        }catch (SQLException ex){
            JOptionPane.showMessageDialog(this, "0 registro não pode ser inserido. Erro: "+ex.getMessage(),"Erro",JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_cadastrarActionPerformed

        
       
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cadastrar;
    private javax.swing.JButton cancelar;
    private javax.swing.JLabel cargahoraria;
    private javax.swing.JTextField cargahorariaTextField;
    private javax.swing.JLabel curso;
    private javax.swing.JTextField cursoTextField;
    private javax.swing.JLabel ementa;
    private javax.swing.JTextArea ementajTextArea;
    private javax.swing.JLabel id;
    private javax.swing.JTextField idTextField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel objetivos;
    private javax.swing.JTextArea objetivosjTextArea;
    private javax.swing.JComboBox periodoComboBox;
    private javax.swing.JLabel periodoLabel;
    private javax.swing.JLabel sigla;
    private javax.swing.JTextField siglaTextField;
    private javax.swing.JLabel titulo;
    private javax.swing.JTextField tituloTextField;
    // End of variables declaration//GEN-END:variables
}
